<style>
    .batchactive{
        background:blue;
    }
    .selected-li {
        border: 2px solid;
    }
</style>
<div ng-include src="'views/sidebar.html'"></div>
<div id="page-wrapper" class="cmsDataDrag" ng-init="init()">
    <br>
    <input type="file" style="display:none;" id="fileuploader" />
    <div class="page-header">
        <h1> 数据面板
        <div class="btn-group pull-right" role="group" aria-label="fn">
        <button class="btn btn-success" ng-click="saveAll($event)">
            <i class="fa fa-floppy-o"></i> 保存
        </button>
        <button class="btn btn-warning" ng-click="revert()">
            <i class="fa fa-undo"></i> 还原
        </button>
        <button class="btn btn-danger" ng-click="publishData()">
            <i class="fa fa-paper-plane"></i> 发布
        </button>
        <a class="btn btn-info" ng-if="pageType==0" href="http://www.tepin.hk/preview/{{pageId}}.html" target="_blank" title="预览"><i class="fa fa-link"></i>预览</a>
        <a class="btn btn-info" ng-if="pageType!=0" href="http://m.tepin.hk/preview/{{pageId}}.html" target="_blank" title="预览"><i class="fa fa-link"></i>预览</a>
        <button class="btn btn-primary" ng-click="viewOnline()">
            <i class="fa fa-link"></i> 浏览线上
        </button>
        </div>
        </h1>
        <small style="color: red;">注意:预览确认后不要遗忘发布!
        </small>
    </div>
    <div class="row" ng-repeat="products in mainproducts" ng-if="products.processorName != 'tabItemListProcessor'">
        <div class="col-md-12">
            <div class="alert alert-info" role="alert" ng-if="products.listId!=0">
                {{getSubModuleName(products.submoduleId)}}， 列表id:{{products.listId}}
                <div class="pull-right btn-group">
                    <a class="btn btn-default" ng-click="copyDataDetail(products.listId)" style="margin-top:-6px;margin-left:2px">
                        <i class="glyphicon glyphicon-copy"></i>复制列表
                    </a>
                    <a class="btn btn-default" ng-click="addDataDetail($event, products.submoduleId, products.listId, time)" style="margin-top:-6px">
                        <i class="fa fa-plus"></i>添加信息
                    </a>
                    <a class="btn btn-default" ng-if='showSearch(products.submoduleId)' ng-click="searchProduct(products.listId, $event)" style="margin-top:-6px">
                        <i class="fa fa-search-plus">搜索添加</i>
                    </a>
                    <div class="btn-group">
                        <a class="btn btn-default dropdown-toggle" ng-if='isItem(products.submoduleId)' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="margin-top:-6px">商品排序<span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu" ng-if='isItem(products.submoduleId)'>
                            <li><a ng-click="sortByPrice(products.cmsData,$index)"><i class="fa fa-sort"></i>价格排序</a></li>
                            <li><a ng-click="sortByStock(products.cmsData,$index)"><i class="fa fa-sort"></i>库存排序</a></li>
                        </ul>
                    </div>
                    <div class="btn-group">
                        <a class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="margin-top:-6px">批量操作 <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li ng-if='isItem(products.submoduleId)'><a href="javascript:" ng-click="deleteSoldOut(products.cmsData)"><i class="fa fa-remove"></i>清除售罄</a></li>
                            <li><a href="javascript:" ng-click="deleteExpire(products.cmsData)"><i class="fa fa-remove"></i>清除过期</a></li>
                            <li><a href="javascript:" ng-click="bantchDeleteCmsData(products.cmsData)"><i class="fa fa-remove"></i>删除选中</a></li>
                            <li><a href="javascript:" style="margin-top:-6px" ng-click="bantchUpdateData(products.cmsData,products.submoduleId)" ng-if='isItem(products.submoduleId)'><i class="fa fa-edit"></i>批量修改</a>
                            </li>
                            <li><a ng-if='isItem(products.submoduleId)' href="data:text/paint; utf-8,{{getItemIds(products)}}" download="items.txt"><i class="fa fa-download"></i>批量导出</a></li>
                        </ul>
                    </div>
                    <label class="btn btn-default" style="margin-top:-6px;">
                        <input type="checkbox" ng-checked="products.allChecked" ng-click="checkAll(products.cmsData,$index)" ng-model="products.allChecked">全选</label>
                </div>
            </div>
            <div class="alert alert-info" role="alert" ng-if="products.listId==0">{{getSubModuleName(products.submoduleId)}}（动态数据）
            </div>
        </div>
        <div>
            <ul dnd-list="products.cmsData" class="list-unstyled product-list" ng-module="products" style="min-height:100px;" >
                <li ng-repeat="item in products.cmsData" dnd-draggable="item" dnd-dragstart="dragStart(products.cmsData)" dnd-moved="products.cmsData.splice($index, 1);itemDrag(products.cmsData, $index, item, event, products)" dnd-effect-allowed="move" dnd-selected="products.selected = item"  ng-class="{'selected': products.selected === item}" >
                    <div ng-if="isItem(products.submoduleId, item)" ng-include="'draggeable.item.html'" class="panel panel-default" ng-class="{success: 'panel-success', danger: 'panel-danger'}[item.parseStatus]">
                    </div>
                    <div ng-if="!isItem(products.submoduleId, item)" ng-include="'draggeable.common.html'" class="panel panel-default" ng-class="{success: 'panel-success', danger: 'panel-danger'}[item.parseStatus]">
                    </div>
                </li>
            </ul>
        </div>
    </div>
    <div class="row" ng-repeat="products in mainproducts" ng-if="products.processorName == 'tabItemListProcessor'">
        <tabset type="pills">
            <tab ng-repeat="tab in tabs" heading="{{tab._name}}" active="tab.active" disable="tab.disabled" select="storeSelectedTab(tab)">
                <div class="col-md-12">
                    <div class="alert alert-info" role="alert">{{getSubModuleName(products.submoduleId)}}， 列表id:{{products.listId}}
                        <div class="pull-right btn-group">
                            <a class="btn btn-default" ng-click="addDataDetail($event, products.submoduleId, products.listId, tab._tag)" style="margin-top:-6px">
                                <i class="fa fa-plus"></i>添加信息
                            </a>
                            <a class="btn btn-default" ng-if='isItem(products.submoduleId)' ng-click="searchProduct(products.listId, $event, tab._tag)" style="margin-top:-6px">
                                <i class="fa fa-search-plus">搜索添加</i>
                            </a>
                            <div class="btn-group">
                                <a class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="margin-top:-6px">
                                批量操作 <span class="caret"></span>
                                </a>
                                <ul class="dropdown-menu">
                                    <li ng-if='isItem(products.submoduleId)'><a href="javascript:" ng-click="deleteSoldOut(tabMaps[products.listId][tab._tag])"><i class="fa fa-remove"></i>清除售罄</a></li>
                                    <li><a href="javascript:" ng-click="deleteExpire(tabMaps[products.listId][tab._tag])"><i class="fa fa-remove"></i>清除过期</a></li>
                                    <li><a href="javascript:" ng-click="bantchDeleteCmsData(tabMaps[products.listId][tab._tag])"><i class="fa fa-remove"></i>删除选中</a></li>
                                    <li><a href="javascript:" ng-click="bantchUpdateData(tabMaps[products.listId][tab._tag],products.submoduleId)"><i class="fa fa-edit"></i>批量修改</a></li>
                                </ul>
                            </div>
                            <label class="btn btn-default" style="margin-top:-6px;">
                                <input type="checkbox" ng-checked="tabMaps[products.listId][tab._tag].allChecked" ng-click="checkAllInTabMap(tabMaps[products.listId][tab._tag],products.listId,tab._tag)" ng-model="tabMaps[products.listId][tab._tag].allChecked">全选</label>
                        </div>
                    </div>
                </div>
                <div>
                    <ul dnd-list="tabMaps[products.listId][tab._tag]" class="list-unstyled product-list" ng-module="products" ng-init="filterByTab(products,tab._tag)" style="min-height:100px;">
                        <li ng-repeat="item in tabMaps[products.listId][tab._tag]" dnd-draggable="item" dnd-moved="tabMaps[products.listId][tab._tag].splice($index,1)" dnd-effect-allowed="move" dnd-selected="products.selected = item" ng-class="{'selected': products.selected === item}">
                            <div ng-if="isItem(products.submoduleId, item)" ng-include="'draggeable.item.html'" class="panel panel-default" ng-class="{success: 'panel-success', danger: 'panel-danger'}[item.parseStatus]">
                            </div>
                            <div ng-if="!isItem(products.submoduleId, item)" ng-include="'draggeable.common.html'" class="panel panel-default" ng-class="{success: 'panel-success', danger: 'panel-danger'}[item.parseStatus]">
                            </div>
                        </li>
                    </ul>
                </div>
            </tab>
        </tabset>
    </div>
</div>
<!--商品列表定制视图-->
<script type="text/ng-template" id="draggeable.item.html">
    <div class="panel-heading clearfix'">
        <div class="btn-group pull-right" role="group" aria-label="...">
            <button ng-click="openDataDetail(item,$event)" class="btn btn-default btn-xs">
                <i class="fa fa-edit"></i>
            </button>
            <button ng-click="deleteProduct(item,$event)" class="btn btn-danger btn-xs">
                <i class="fa fa-remove"></i>
            </button>
        </div>
        <div class="panel-title">
            <input type="checkbox" ng-checked="item.checked" ng-model="item.checked"  style="position: absolute;left: 2px;top: -4px;" />{{getItemInfoValue(item.properties, "name")}}
        </div>
    </div>
    <div class="panel-body" ng-if="hasImg(item.properties)" ng-class="{true:'selected-li'}[item.checked]">
        <a href="#" class="thumbnail" ng-click="openDataDetail(item,$event)">
            <img ng-src="{{parseImg(item.properties)}}@200h">
            <div ng-if="getStatusOfItem(item.properties) == 1" class="icon icon-soldout icon-soldout-normal" style="">正常售罄</div>
            <div ng-if="getStatusOfItem(item.properties) == 2" class="icon icon-soldout icon-soldout-normal" style="">一键售罄</div>
            <div ng-if="getStatusOfItem(item.properties) == 3" class="icon icon-soldout icon-soldout-normal" style="">下架</div>
        </a>
    </div>
    <div class="panel-footer">
        <div class="panel-title">商品ID:<strong>{{getItemInfoValue(item.properties, "itemId")}}</strong></div>
        <div class="panel-title">名称: <strong>{{getItemInfoValue(item.properties, "name")}}</strong></div>
        <div class="panel-title">库存: <strong>{{getItemInfoValue(item.properties, '_stock')}}</strong></div>
        <div class="panel-title">当前售价: <strong>￥{{getItemInfoValue(item.properties, "_price")/100}}</strong></div>
        <div class="panel-title" ng-repeat="temp in item.properties">
            <div ng-if="temp.field.fieldType == 'Date'">
                {{temp.field.fieldDescription}} : {{temp.propertyValue | date : 'yyyy-MM-dd HH:mm'}}
            </div>
        </div>
    </div>
</script>
<!--通用列表定制视图-->
<script type="text/ng-template" id="draggeable.common.html">
    <div class="panel-heading clearfix">
        <div class="btn-group pull-right" role="group" aria-label="...">
            <button ng-click="openDataDetail(item,$event)" class="btn btn-default btn-xs">
                <i class="fa fa-edit"></i>
            </button>
            <button ng-click="deleteProduct(item,$event)" class="btn btn-danger btn-xs">
                <i class="fa fa-remove"></i>
            </button>
        </div>
        <!--非商品列表视图-->
        <div class="panel-title">
            <input type="checkbox" ng-checked="item.checked" ng-model="item.checked" style="position: absolute;left: 2px;top: -4px;" />数据{{$index+1}}</div>
    </div>
    <div class="panel-body" ng-if="hasImg(item.properties)">
        <a href="#" class="thumbnail" ng-click="openDataDetail(item,$event)">
            <img ng-src="{{parseImg(item.properties)}}@200h">
        </a>
    </div>
    <div class="panel-footer">
        <div ng-repeat="temp in filerShowProperties(item.properties)" class="panel-title">
            <div ng-if="temp.field.fieldType != 'Date'">
                <label>{{temp.field.fieldDescription}} : {{temp.propertyValue}}</label>
            </div>
            <div ng-if="temp.field.fieldType == 'Date'">
                <label>{{temp.field.fieldDescription}} : {{temp.propertyValue | date : 'yyyy-MM-dd HH:mm'}}</label>
            </div>
        </div>
    </div>
</script>
<div ng-include src="'views/common/common.module.data.html'"></div>
